<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户昵称" prop="userNick">
        <el-input
          v-model="queryParams.userNick"
          placeholder="请输入用户昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户邮箱" prop="userEmail">
        <el-input
          v-model="queryParams.userEmail"
          placeholder="请输入用户邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付密码" prop="payWord">
        <el-input
          v-model="queryParams.payWord"
          placeholder="请输入支付密码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="钱" prop="money">
        <el-input
          v-model="queryParams.money"
          placeholder="请输入钱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮箱密码" prop="emailWord">
        <el-input
          v-model="queryParams.emailWord"
          placeholder="请输入邮箱密码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机登录密码" prop="phoneWord">
        <el-input
          v-model="queryParams.phoneWord"
          placeholder="请输入手机登录密码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="苹果机唯一编号" prop="appId">
        <el-input
          v-model="queryParams.appId"
          placeholder="请输入苹果机唯一编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户状态0-正常；1-金庸" prop="userStatus">
        <el-select v-model="queryParams.userStatus" placeholder="请选择用户状态0-正常；1-金庸" clearable>
          <el-option
            v-for="dict in dict.type.sys_normal_disable"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="版本号" prop="version">
        <el-input
          v-model="queryParams.version"
          placeholder="请输入版本号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="缴纳保证金金额" prop="bailMoney">
        <el-input
          v-model="queryParams.bailMoney"
          placeholder="请输入缴纳保证金金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="当前账户语言类型编码" prop="langCode">
        <el-input
          v-model="queryParams.langCode"
          placeholder="请输入当前账户语言类型编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="会员id" prop="vipId">
        <el-input
          v-model="queryParams.vipId"
          placeholder="请输入会员id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任务接取数量" prop="accessNum">
        <el-input
          v-model="queryParams.accessNum"
          placeholder="请输入任务接取数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="任务接取更新时间" prop="accessTime">
        <el-input
          v-model="queryParams.accessTime"
          placeholder="请输入任务接取更新时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="累计收益" prop="earnings">
        <el-input
          v-model="queryParams.earnings"
          placeholder="请输入累计收益"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="父类id" prop="parentId">
        <el-input
          v-model="queryParams.parentId"
          placeholder="请输入父类id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户唯一邀请码" prop="userCode">
        <el-input
          v-model="queryParams.userCode"
          placeholder="请输入用户唯一邀请码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="头像" prop="avatar">
        <el-input
          v-model="queryParams.avatar"
          placeholder="请输入头像"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="冻结金额" prop="freezMoney">
        <el-input
          v-model="queryParams.freezMoney"
          placeholder="请输入冻结金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="转盘次数" prop="turntableNum">
        <el-input
          v-model="queryParams.turntableNum"
          placeholder="请输入转盘次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:tuserInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:tuserInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:tuserInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:tuserInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tuserInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="用户表id" align="center" prop="id" />
      <el-table-column label="用户昵称" align="center" prop="userNick" />
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="用户邮箱" align="center" prop="userEmail" />
      <el-table-column label="支付密码" align="center" prop="payWord" />
      <el-table-column label="钱" align="center" prop="money" />
      <el-table-column label="邮箱密码" align="center" prop="emailWord" />
      <el-table-column label="手机登录密码" align="center" prop="phoneWord" />
      <el-table-column label="苹果机唯一编号" align="center" prop="appId" />
      <el-table-column label="用户状态0-正常；1-金庸" align="center" prop="userStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.userStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="版本号" align="center" prop="version" />
      <el-table-column label="缴纳保证金金额" align="center" prop="bailMoney" />
      <el-table-column label="当前账户语言类型编码" align="center" prop="langCode" />
      <el-table-column label="会员id" align="center" prop="vipId" />
      <el-table-column label="任务接取数量" align="center" prop="accessNum" />
      <el-table-column label="任务接取更新时间" align="center" prop="accessTime" />
      <el-table-column label="累计收益" align="center" prop="earnings" />
      <el-table-column label="父类id" align="center" prop="parentId" />
      <el-table-column label="用户唯一邀请码" align="center" prop="userCode" />
      <el-table-column label="头像" align="center" prop="avatar" />
      <el-table-column label="冻结金额" align="center" prop="freezMoney" />
      <el-table-column label="转盘次数" align="center" prop="turntableNum" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:tuserInfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:tuserInfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用户信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户昵称" prop="userNick">
          <el-input v-model="form.userNick" placeholder="请输入用户昵称" />
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="用户邮箱" prop="userEmail">
          <el-input v-model="form.userEmail" placeholder="请输入用户邮箱" />
        </el-form-item>
        <el-form-item label="支付密码" prop="payWord">
          <el-input v-model="form.payWord" placeholder="请输入支付密码" />
        </el-form-item>
        <el-form-item label="钱" prop="money">
          <el-input v-model="form.money" placeholder="请输入钱" />
        </el-form-item>
        <el-form-item label="邮箱密码" prop="emailWord">
          <el-input v-model="form.emailWord" placeholder="请输入邮箱密码" />
        </el-form-item>
        <el-form-item label="手机登录密码" prop="phoneWord">
          <el-input v-model="form.phoneWord" placeholder="请输入手机登录密码" />
        </el-form-item>
        <el-form-item label="苹果机唯一编号" prop="appId">
          <el-input v-model="form.appId" placeholder="请输入苹果机唯一编号" />
        </el-form-item>
        <el-form-item label="用户状态0-正常；1-金庸" prop="userStatus">
          <el-select v-model="form.userStatus" placeholder="请选择用户状态0-正常；1-金庸">
            <el-option
              v-for="dict in dict.type.sys_normal_disable"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="版本号" prop="version">
          <el-input v-model="form.version" placeholder="请输入版本号" />
        </el-form-item>
        <el-form-item label="缴纳保证金金额" prop="bailMoney">
          <el-input v-model="form.bailMoney" placeholder="请输入缴纳保证金金额" />
        </el-form-item>
        <el-form-item label="当前账户语言类型编码" prop="langCode">
          <el-input v-model="form.langCode" placeholder="请输入当前账户语言类型编码" />
        </el-form-item>
        <el-form-item label="会员id" prop="vipId">
          <el-input v-model="form.vipId" placeholder="请输入会员id" />
        </el-form-item>
        <el-form-item label="任务接取数量" prop="accessNum">
          <el-input v-model="form.accessNum" placeholder="请输入任务接取数量" />
        </el-form-item>
        <el-form-item label="任务接取更新时间" prop="accessTime">
          <el-input v-model="form.accessTime" placeholder="请输入任务接取更新时间" />
        </el-form-item>
        <el-form-item label="累计收益" prop="earnings">
          <el-input v-model="form.earnings" placeholder="请输入累计收益" />
        </el-form-item>
        <el-form-item label="父类id" prop="parentId">
          <el-input v-model="form.parentId" placeholder="请输入父类id" />
        </el-form-item>
        <el-form-item label="用户唯一邀请码" prop="userCode">
          <el-input v-model="form.userCode" placeholder="请输入用户唯一邀请码" />
        </el-form-item>
        <el-form-item label="头像" prop="avatar">
          <el-input v-model="form.avatar" placeholder="请输入头像" />
        </el-form-item>
        <el-form-item label="冻结金额" prop="freezMoney">
          <el-input v-model="form.freezMoney" placeholder="请输入冻结金额" />
        </el-form-item>
        <el-form-item label="转盘次数" prop="turntableNum">
          <el-input v-model="form.turntableNum" placeholder="请输入转盘次数" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTuserInfo, getTuserInfo, delTuserInfo, addTuserInfo, updateTuserInfo } from "@/api/system/tuserInfo";

export default {
  name: "TuserInfo",
  dicts: ['sys_normal_disable'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户信息表格数据
      tuserInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userNick: null,
        phone: null,
        userEmail: null,
        payWord: null,
        money: null,
        emailWord: null,
        phoneWord: null,
        appId: null,
        userStatus: null,
        version: null,
        bailMoney: null,
        langCode: null,
        vipId: null,
        accessNum: null,
        accessTime: null,
        earnings: null,
        parentId: null,
        userCode: null,
        avatar: null,
        freezMoney: null,
        turntableNum: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户信息列表 */
    getList() {
      this.loading = true;
      listTuserInfo(this.queryParams).then(response => {
        this.tuserInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userNick: null,
        phone: null,
        userEmail: null,
        payWord: null,
        money: null,
        emailWord: null,
        phoneWord: null,
        appId: null,
        userStatus: null,
        version: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        bailMoney: null,
        langCode: null,
        vipId: null,
        accessNum: null,
        accessTime: null,
        earnings: null,
        parentId: null,
        userCode: null,
        avatar: null,
        freezMoney: null,
        turntableNum: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTuserInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改用户信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTuserInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTuserInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除用户信息编号为"' + ids + '"的数据项？').then(function() {
        return delTuserInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/tuserInfo/export', {
        ...this.queryParams
      }, `tuserInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
